/**
 * @project sso-token-start V1.0
 * @Title:  TokenClientConfig.java  
 * @Package com.gitee.kinbug.token.config 
 * Copyright(c) 2020 KinBug Co. Ltd. 
 * All right reserved. 
 */
package com.gitee.kinbug.sso.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.gitee.kinbug.sso.filter.SsoTokenFilter;
import com.gitee.kinbug.sso.properties.SsoTokenProperties;
import com.gitee.kinbug.sso.store.SsoServiceStore;
import lombok.extern.slf4j.Slf4j;

/**
 * Description:TODO(token客户端配置)
 * @author: KinBug
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "kinbug.sso.is-client", matchIfMissing = false)
@EnableConfigurationProperties(SsoTokenProperties.class)
public class TokenClientConfig {
	
	@Autowired
	private SsoTokenProperties ssoTokenProperties;
	
	@Bean
	public FilterRegistrationBean<SsoTokenFilter> SsoFilterRegistration() {
		FilterRegistrationBean<SsoTokenFilter> registration = new FilterRegistrationBean<SsoTokenFilter>();
		registration.setName("SsoTokenFilter");
		registration.setOrder(1);
		registration.addUrlPatterns("/*");
		registration.setFilter(new SsoTokenFilter(ssoTokenProperties));
		return registration;
	}
	
	@Bean
	public SsoServiceStore ssoClientStore() {
		log.info(">>>>>>>>>>client token验证的KEY: "+ssoTokenProperties.getAuthKey());
		log.info(">>>>>>client 登录用户SESSION的KEY: "+ssoTokenProperties.getLoginUser());
		return new SsoServiceStore(ssoTokenProperties);
	}
}
